/**
 * 
 */
package wangjg.xuexiban.activity.card;

import java.util.List;

import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;

/**
 * @author wangjg
 *
 */
public class ListPagerAdapter extends PagerAdapter{
	List list = null;
	SparseArray<View> sa = new SparseArray<View>();
	
	public ListPagerAdapter(List list){
		this.list = list;
	}
	
	public int getCount() {
		return list.size();
	}
	
	public Object instantiateItem(View container, int position) {
		Log.i(this.getClass().getName(), "instantiateItem, position=" + position	+ ", container=" + container);
		View view = sa.get(position);
		if(view==null){
			view = this.getItemView(position);
			sa.put(position, view);
		}
		((ViewPager) container).addView(view);
		return view;
	}

	protected View getItemView(int position) {
		return null;
	}

	public void destroyItem(View container, int position, Object object) {
		Log.i(this.getClass().getName(), "destroyItem,position=" + position	+ ",object=" + object);
		((ViewPager)container).removeView((View) object);
		sa.remove(position);
	}
	
	public boolean isViewFromObject(View view, Object object) {
		return view == (object);
	}
	
	public Parcelable saveState() {
		return null;
	}
	
	public void restoreState(Parcelable state, ClassLoader loader) {
	}
	
	public void startUpdate(View container) {
	}
	
	public void finishUpdate(View container) {
	}
}